﻿using EntityCreater.Entity;
using EntityCreater.Service;
using NetDimension.WinForm;
using SQLBuilder.Repositories;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace EntityCreater
{
    public partial class FrmMain : ModernUIForm
    {
       
        public FrmMain()
        {
            InitializeComponent();

            this.lblTitle.Font = new System.Drawing.Font("微软雅黑", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            CGlobal.OnSendMsgToMain =
        }
        private void Say()
        {
            MessageBox.Show("哈");
        }

        private void btnCheck_Click(object sender, EventArgs e)
        {
            var path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, ALLConfig.DataBase);
            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);

            var list = CoreService.GetTableInfoByConnStr(ALLConfig.ConnStr);
            list.ForEach(x =>
            {
                var entities = CoreService.GetFieldListByTableName(x.TableName, ALLConfig.ConnStr);
                WriteService.WriteEntityToFile(entities, new Entity.CreaterInfo()
                {
                    CreateDate = DateTime.Now.ToString(),
                    DataBase = ALLConfig.DataBase,
                    CreateName = "邓振振",
                    NameSpace = txtNameSpace.Text.Trim()
                });
            });
            MessageBox.Show("ok");
            Process.Start(path);
        }

        #region 样式
        private void FrmMain_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();
            SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
        }
        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();
        [DllImport("user32.dll")]
        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
        public const int WM_SYSCOMMAND = 0x0112;
        public const int SC_MOVE = 0xF010;
        public const int HTCAPTION = 0x0002;
        private void lblTitle_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();
            SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
        }
        #endregion

        private void btnExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void tsDBConnectSetting_Click(object sender, EventArgs e)
        {
            new FrmConnStrConfig().ShowDialog();
        }

        private void tsCodeSetting_Click(object sender, EventArgs e)
        {
            new FrmCodeSetting().ShowDialog();
        }
    }
}
